package com.zhlb.zfba.modules.sys.web;


import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.zhlb.zfba.modules.per.bean.PoliceInfo;
import com.zhlb.zfba.modules.per.bean.SuspectInfo;
import com.zhlb.zfba.modules.per.bean.UserInfo;
import com.zhlb.zfba.modules.per.service.PoliceInfoService;
import com.zhlb.zfba.modules.per.service.SuspectInfoService;
import com.zhlb.zfba.modules.per.service.UserInfoService;
import com.zhlb.zfba.modules.sys.service.SysService;

@Controller
@RequestMapping(value = "/sys/view")
public class SysController {
	@Autowired 
	SysService sysService;
	@Autowired 
	PoliceInfoService policeInfoService;
	@Autowired
	SuspectInfoService suspectInfoService;
	@RequestMapping(value = {"main",""})
	public String main() {
		return "modules/sys/main";
	}
	@RequestMapping(value = {"left"})
	public String left() {
		return "modules/sys/left";
	}
	@RequestMapping(value = {"top"})
	public String top(Model model) {
		//获取当前在所人数
		PoliceInfo policeInfo =new PoliceInfo();
		policeInfo.setIsLeave("0");
		List<PoliceInfo> policeInfoList=policeInfoService.findList(policeInfo);
		SuspectInfo suspectInfo =new SuspectInfo();
		suspectInfo.setIsLeave("0");
		List<SuspectInfo> suspectInfoList=suspectInfoService.findList(suspectInfo);
		Integer policeInfoNum=policeInfoList==null?0:policeInfoList.size(); 
		Integer suspectInfoNum=suspectInfoList==null?0:suspectInfoList.size(); 
		model.addAttribute("policeInfoNum",policeInfoNum);
		model.addAttribute("suspectInfoNum",suspectInfoNum);
		
		return "modules/sys/top";
	}
	@RequestMapping(value = {"footer"})
	public String footer() {
		return "modules/sys/footer";
	}
	@RequestMapping(value = {"login"})
	public String login() {
		return "modules/sys/login";
	}
	@RequestMapping(value = {"loginauth"})
	public String loginauth(UserInfo userInfo,HttpServletRequest request,Model model) {
		String msg=sysService.loginAuth(userInfo, request);
		model.addAttribute("userInfo",userInfo);
		if("".equals(msg)){
			return "modules/sys/main";
		}else{
			model.addAttribute("msg", msg);
			return "modules/sys/login";
		}
		
	}
	@RequestMapping(value = {"logout"})
	public String logout(HttpServletRequest request) {
		HttpSession session=request.getSession(false);
		if(session!=null){
			session.invalidate();
		}
		return "modules/sys/login";
	}
}
